package com.huawei.hwCloudJs.service.http.a;

import android.text.TextUtils;
import android.util.Log;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.framework.network.restclient.hwhttp.RequestBody;
import com.huawei.hwCloudJs.service.http.annotation.RequestField;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;

public abstract class a<T extends d> extends c<T> {
    private void a(Field field, StringBuffer stringBuffer) throws IllegalAccessException, UnsupportedEncodingException {
        String value = ((RequestField) field.getAnnotation(RequestField.class)).value();
        if (TextUtils.isEmpty(value)) {
            value = field.getName();
        }
        boolean isAccessible = field.isAccessible();
        field.setAccessible(true);
        Object obj = field.get(this);
        if (obj != null) {
            value = value + ContainerUtils.KEY_VALUE_DELIMITER + URLEncoder.encode(obj.toString(), "UTF-8");
            if (stringBuffer.length() != 0) {
                value = ContainerUtils.FIELD_DELIMITER + value;
            }
            stringBuffer.append(value);
        }
        field.setAccessible(isAccessible);
    }

    public String h() {
        StringBuffer stringBuffer = new StringBuffer();
        for (Field field : getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(RequestField.class)) {
                try {
                    a(field, stringBuffer);
                } catch (IllegalAccessException e) {
                    Log.e("FormBean", "setField IllegalAccessException");
                } catch (UnsupportedEncodingException e2) {
                    Log.e("FormBean", "setField UnsupportedEncodingException");
                }
            }
        }
        return stringBuffer.toString();
    }

    public String i() {
        return RequestBody.HEAD_VALUE_CONTENT_TYPE_URLENCODED;
    }

    public String j() {
        return "POST";
    }
}
